include ../../build/Make.conf

COMPILE_LIB_HOME=../../lib

INC     = -I. -I $(CORE_HOME) 
OPT     = -pipe -fno-ident -fPIC -shared -z defs
LINK    = -lpthread

ARCH = $(shell $(CC) $(DEBUG) -E -DARCHTEST $(BUILD_DIR)/conftest.c|grep 86)
ifeq ($(ARCH),i386)
CFLAGS += $(shell $(BUILD_DIR)/conftest.sh "$(CC)" -march=pentium3 "$(BUILD_DIR)")
else
ifeq ($(ARCH),x86_64)
else
echo $(error Unsupported Compiler, CC=$(CC) ARCH=$(ARCH)))
endif
endif

CFLAGS += $(OPT) -g -pg -Wall -D_GNU_SOURCE -funroll-loops -MMD -D_REENTRANT
CFLAGS += $(shell $(BUILD_DIR)/conftest.sh "$(CC)" -ftracer "$(BUILD_DIR)")
CFLAGS += $(shell $(BUILD_DIR)/conftest.sh "$(CC)" -ftree-vectorize "$(BUILD_DIR)")
ifeq ($(MEMCHECK),1)
CFLAGS += -DMEMCHECK
endif
CXXFLAGS := $(CFLAGS)
CXXFLAGS += $(shell $(BUILD_DIR)/conftest.sh "$(CXX)" -fno-rtti "$(BUILD_DIR)")

SRCS = 	MarkupSTL.cpp \
        net.cpp \
        log.cpp \
        memcheck.cpp \
        poller.cpp \
#poll_thread.cpp
#DYNAMIC_NAME= libcore-gcc$(GCCVER)-ver$(COMM_LIB_VER)
DYNAMIC_NAME = libcore.a
DYNAMIC_LIB	= $(COMPILE_LIB_HOME)/$(DYNAMIC_NAME)

all: $(DYNAMIC_LIB)

$(DYNAMIC_LIB): $(SRCS:.cpp=.o)
	@ar cru $@ $^
#	@-ln -sf $(DYNAMIC_NAME) $(COMPILE_LIB_HOME)/libcore.so

%.o: %.c Makefile
	$(CC) $(CFLAGS) $(INC) -c -pg -o $@ $<
	@-mv -f $*.d .dep.$@
%.o: %.cc Makefile
	$(CXX) $(CXXFLAGS) $(INC) -c -pg -o $@ $<
	@-mv -f $*.d .dep.$@
%.o: %.cpp Makefile
	$(CXX) $(CXXFLAGS) $(INC) -c -pg -o $@ $<
	@-mv -f $*.d .dep.$@
clean:
	rm -f *.o .po *.so *.d .dep.* $(DYNAMIC_LIB) $(COMPILE_LIB_HOME)/libcore.so
-include /dev/null $(wildcard .dep.*) 
